package com.campus.mapper;

import com.campus.domain.entity.CommentReply;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 评论回复Mapper
 */
@Mapper
public interface CommentReplyMapper {
    
    // 插入回复
    @Insert("INSERT INTO comment_replies(comment_id, user_id, reply_to_user_id, content, like_count) " +
            "VALUES(#{commentId}, #{userId}, #{replyToUserId}, #{content}, 0)")
    int insert(CommentReply reply);
    
    // 根据评论ID查询回复
    @Select("SELECT * FROM comment_replies WHERE comment_id = #{commentId} AND is_deleted = 0 ORDER BY create_time")
    List<CommentReply> selectByCommentId(Long commentId);
    
    // 根据ID查询回复
    @Select("SELECT * FROM comment_replies WHERE id = #{id} AND is_deleted = 0")
    CommentReply selectById(Long id);
    
    // 删除回复（逻辑删除）
    @Update("UPDATE comment_replies SET is_deleted = 1 WHERE id = #{id}")
    int deleteById(Long id);
    
    // 增加点赞数
    @Update("UPDATE comment_replies SET like_count = like_count + 1 WHERE id = #{id}")
    int incrementLikeCount(Long id);
    
    // 减少点赞数
    @Update("UPDATE comment_replies SET like_count = like_count - 1 WHERE id = #{id}")
    int decrementLikeCount(Long id);
}

